package org.example.controller;


import lombok.RequiredArgsConstructor;
import org.apache.commons.lang.StringUtils;
import org.example.domain.ResponseResult;
import org.example.domain.dto.GalleryListDto;
import org.example.domain.entity.Gallery;
import org.example.enums.AppHttpCodeEnum;
import org.example.exception.SystemException;
import org.example.service.GalleryService;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/gallery")
@RequiredArgsConstructor
public class GalleryController {

    private final GalleryService galleryService;


    @PostMapping("/addGallery")
    public ResponseResult addGallery(@RequestBody Gallery gallery){
        if(StringUtils.isBlank(gallery.getUrl())){
            throw new SystemException(AppHttpCodeEnum.NOT_GALLERY_URL_ERROR);
        }
        return galleryService.addGallery(gallery);
    }

    @PostMapping("/galleryList")
    public ResponseResult galleryList(@RequestBody GalleryListDto galleryListDto){

        return galleryService.galleryList(galleryListDto);
    }

    @PutMapping("/updateGallery")
    public ResponseResult updateGallery(@RequestBody Gallery gallery){
        if(StringUtils.isBlank(gallery.getUrl())){
            throw new SystemException(AppHttpCodeEnum.NOT_GALLERY_URL_ERROR);
        }
        return galleryService.updateGallery(gallery);
    }

}
